<?php
namespace app\admin\model;

use think\Model;
                    

class Foreknowledge extends Model
                    
{
                    
    public function getAll($where){
                    
        $rs = Foreknowledge::where($where)
                    
        ->select();
                    
        return $rs;
                    
    }

    public function getPageAll($where){

        $rs = Foreknowledge::where($where)

            ->order('sort desc')

            ->paginate(50);

        return $rs;

    }
                    
    public function getOne($where){
                    
        $rs = Foreknowledge::where($where)
                    
        ->find();
                    
        return $rs;
                    
    }
                    
    public function add($data){
                    
        $rs = Foreknowledge::data($data)
                    
        ->save();
                    
        return $rs;
                    
    }
                    
    public function edit($where,$data){
                    
        $rs = Foreknowledge::where($where)
                    
        ->update($data);
                    
        return $rs;
                    
    }
                    
    public function del($where){
                    
        $rs = Foreknowledge::where($where)
                    
        ->delete();
                    
        return $rs;
                    
    }

    public function detailJoin($where){
        $rs = Foreknowledge::alias('fo')

            ->where('fo.id','=',$where['id'])

            ->join('foreknowledge_type ft','ft.id = fo.type','LEFT')

            ->field('fo.*,ft.name as ft_name,ft.id as ft_id')

            ->find();

        return $rs;
    }

    public function totalNum(){
        $rs = Foreknowledge::count('id');
        return $rs;
    }

    public function totalNumWhere($where){
        $rs = Foreknowledge::where($where)
            ->count('id');
        return $rs;
    }
                    
}
                    
